package la.bbs558.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import la.bbs558.dao.UserTagDao;
import la.bbs558.entity.UserTag;
import la.bbs558.entity.vo.UserTagVO;
import la.bbs558.satoken.StpAdminUtil;
import la.bbs558.service.UserTagService;
import la.bbs558.util.Objs;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Shanks
 * @date: 2023/12/15 17:01
 * @desc:
 */
@Service
@RequiredArgsConstructor
public class UserTagServiceImpl extends ServiceImpl<UserTagDao, UserTag> implements UserTagService {

    private final UserTagDao userTagDao;

    @Override
    public List<UserTagVO> getListForAdmin(String tagName) {
        return userTagDao.selectListForAdmin(tagName);
    }

    @Override
    public void addUserTagForAdmin(UserTag userTag) {
        userTagDao.insert(new UserTag()
                .setTagName(userTag.getTagName())
                .setStart(userTag.getStart())
                .setEnd(userTag.getEnd())
                .setCreateUser(StpAdminUtil.getLoginIdAsLong()));
    }

    @Override
    public void updateUserTagForAdmin(UserTag userTag) {
        Objs.valid(userTag.getId(), "id不能为空");
        userTagDao.updateById(new UserTag()
                .setId(userTag.getId())
                .setTagName(userTag.getTagName())
                .setStart(userTag.getStart())
                .setEnd(userTag.getEnd()));
    }
}
